﻿using MODEL;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace DAL
{
   public class SchedulingDAL
    {
        #region 存储过程，车辆调度
        /// <summary>
        /// 存储过程，车辆调度
        /// </summary>
        /// <returns></returns>
        public List<CarrierinfoMODEL> GetCarriens()
        {
            string sql = "Proc_GetPagedSchedulinglist";
            List<CarrierinfoMODEL> list = new List<CarrierinfoMODEL>();
            SqlDataReader reader = DBhelper.ExecuteReaderProc(sql);
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    list.Add(new CarrierinfoMODEL()
                    {
                        CarriersID = Convert.ToInt32(reader["CarriersID"]),
                        SendAddress = reader["SendAddress"].ToString(),
                        FK_ReceiveAddress = reader["FK_ReceiveAddress"].ToString(),
                        LeaverDate = Convert.ToDateTime(reader["LeaverDate"])
                    });
                }
                reader.Close();
            }
            return list;
        }
        #endregion

        #region 存储过程，当前车辆调度
        /// <summary>
        /// 存储过程，当前车辆调度
        /// </summary>
        /// <returns></returns>
        public List<TruckSchedulingMODEL> GetTruckScheduList()
        {
            string truck = "proc_GetTruck";
            List<TruckSchedulingMODEL> list = new List<TruckSchedulingMODEL>();
            SqlDataReader reader = DBhelper.ExecuteReaderProc(truck);
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    list.Add(new TruckSchedulingMODEL()
                    {
                        TruckID = Convert.ToInt32(reader["TruckID"]),
                        Number = reader["Number"].ToString(),
                        Type=reader["Type"].ToString(),
                        TeamName = reader["TeamName"].ToString(),
                        Name = reader["Name"].ToString(),
                        Length = reader["Length"].ToString(),
                        Tonngae = Convert.ToInt32(reader["Tonngae"])
                    });
                }
                reader.Close();
            }
            return list;
        }
        #endregion

        #region 当前可调度车辆调度
        /// <summary>
        /// 当前可调度车辆调度
        /// </summary>
        /// <param name="truckid"></param>
        /// <param name="carriesid"></param>
        /// <param name="userid"></param>
        public void GetDiaoDuTruck(int truckid, int carriesid, int userid)
        {
            string procname = "proc_GetPadeScheling";
            SqlParameter[] parm = {
                new SqlParameter("@TruckID",truckid),
                new SqlParameter("@CarriersID",carriesid),
                new SqlParameter("@UserID",userid)
            };
            DBhelper.ExecuteNonQueryProc(procname, parm);
        }
        #endregion
    }
}
